package com.yang.proxy.dynamicproxy.myjdk;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author yang
 * @version 0.1
 * @date 2019/4/15
 */
public class MyJDKProxy implements MyInvocationHandler {

    private Object object = null;

    public MyJDKProxy(Object object) {
        this.object = object;
    }

    public Object proxy() throws IOException {
        return MyProxy.newProxyInstance(new MyClassLoader(), object.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
        System.out.println("寻找房源");
        Object o = method.invoke(object, args);
        System.out.println("签署合同");
        return o;
    }
}
